/********************************************************************
 
 Copyright (C), 2012年 dhc. All rights reserved.
 
 Filename: 	    MailDetailMessage.m 
 
 Author:        muzongcun
 
 Version:       1.0
 
 Description:   MailDetailMessage
 
 History:
 
 muzongcun    2012/3/10     1.0     Create
 
 *********************************************************************/
#import "MailDetailMessage.h"
#import "AppDelegate.h"
#import "MailMessageComposer.h"
#import "NavigationMainViewController.h"
#import "XmlRpc.h"
#import "Session.h"
#import "WebViewContrller.h"
#import "myToast.h"
#import "TaskManager.h"
@implementation MailDetailMessage

@synthesize m_rect;
@synthesize m_navBar;
@synthesize m_sendLabel;         //发件人
@synthesize m_dateLabel;
@synthesize m_subjectLabel;      //发件标题
@synthesize m_contentLabel;
@synthesize m_mailList;
@synthesize m_contentWebView;
@synthesize m_mailDetailInfo;
@synthesize m_mailListInfo;  
#undef _BUTTON_PRESS 

//******************************************************
// Method:     initWithNibName
// Access:     public 
// Returns:    void
// Parameter:  nibNameOrNil
// Parameter:  nibBundleOrNil
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{
	if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) 
	{
		m_toArray = [[NSMutableArray alloc] initWithCapacity:10];

        m_boxType = -1;
        
		m_offsetFlag        = NO;
        m_bThreadFresh      = NO; //默认非线程刷新
        m_bNextPriorDetail  = NO; //前一个 下一个 邮件详细
        m_bIsBack           = NO;
        m_condition = [[NSCondition alloc]init];
	}
	return self;
}

//******************************************************
// Method:     initWithNibName
// Access:     public 
// Returns:    void
// Parameter:  nibNameOrNil
// Parameter:  nibBundleOrNil
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil receiverObj:(NSDictionary*)rec
{
	m_receiverObj = [rec retain];
	
	return [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
}

//******************************************************
// Method:     initWithOwner
// Access:     public 
// Returns:    void
// Parameter:  owner
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (id)initWithOwner:(UIViewController *)owner
{
    
    NSLog(@"gogo");
    
    UIButton *playNowButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 20, 20, 40)];
    playNowButton.titleLabel.text=@"往期";
    // [playNowButton setBackgroundImage:[UIImage imageNamed:@"right.png"] forState:UIControlStateNormal];
    
    [playNowButton addTarget:self action:@selector(AgoList) forControlEvents:UIControlEventTouchDown];
    
    UIBarButtonItem *bar =[[UIBarButtonItem alloc] initWithCustomView:playNowButton];
    
    [playNowButton release];
    
    //self.buttonOwner = owner;
    
    return (id)bar;
    
}

//******************************************************
// Method:     viewDidLoad
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)viewDidLoad 
{
    NSLog(@"[MailDetailMessage]-[viewDidLoad]---start");
    


    /*----------最上面的navigaitonBar topbar---------*/
    m_navBar=[[UINavigationBar alloc]init];
    m_navBar.frame = CGRectMake(0, 0, 320, 44);
    
    UIImage* imageBar = [UIImage imageNamed:PIC_MAIL_TOP_BAR];

    NSString* devVersion = [[UIDevice currentDevice] systemVersion];
    if ([devVersion compare:@"4.3.3"] == 0)
    {
        [m_navBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)];
        [m_navBar setTintColor:NAVIGATION_BAR_COLOR];
    }else
    {
        [m_navBar setBackgroundImage:imageBar forBarMetrics:UIBarMetricsDefault];
    }
    
    /*----------返回按钮---------*/
    m_barRetBut = [[UIButton alloc] initWithFrame:CGRectMake(5.0, 10.0, 50.0, 25.0)];
    [m_barRetBut setTitle:@" 返回" forState:UIControlStateNormal];
    UIFont *font              = [UIFont systemFontOfSize:14];
    m_barRetBut.titleLabel.font = font;
    UIImage *barRetImageNormal = [UIImage imageNamed:PIC_MAIL_SWITCH_SELF_NORMAL];
    [m_barRetBut setBackgroundImage:barRetImageNormal forState:UIControlStateNormal];
    //[barRetImageNormal release];
    UIImage *barRetImagePressed = [UIImage imageNamed:PIC_MAIL_SWITCH_SELF_PRESS];
    [m_barRetBut setBackgroundImage:barRetImagePressed forState:UIControlStateHighlighted];
    //[barRetImagePressed release];
    [m_barRetBut addTarget:self action:@selector(onReturn) forControlEvents:UIControlEventTouchUpInside];
    m_barRetBut.enabled = NO;
    
    /*----------归并---------*/
    m_barMergeBut = [[UIButton alloc] initWithFrame:CGRectMake(65.0, 0.0, 55.5, 44.0)];
    UIImage *barMergeButImageNormal = [UIImage imageNamed:PIC_MAIL_MERGE_NORMAL];
    UIImage *barMergeButImagePress = [UIImage imageNamed:PIC_MAIL_MERGE_PRESS];
    [m_barMergeBut setBackgroundImage:barMergeButImageNormal forState:UIControlStateNormal];
    [m_barMergeBut setBackgroundImage:barMergeButImagePress forState:UIControlStateHighlighted];
    [m_barMergeBut addTarget:self action:@selector(onMerge) forControlEvents:UIControlEventTouchUpInside];
    
    //回复按钮
    m_barRevertBut = [[UIButton alloc] initWithFrame:CGRectMake(115.0, 0.0, 55.5, 44.0)];
    [m_barRevertBut setTitle:@"" forState:UIControlStateNormal];
    UIImage *barRevertImageNormal = [UIImage imageNamed:PIC_MAIL_REVERT_NORMAL];
    UIImage *barRevertImagePress = [UIImage imageNamed:PIC_MAIL_REVERT_PRESS];
    [m_barRevertBut setBackgroundImage:barRevertImageNormal forState:UIControlStateNormal];
    [m_barRevertBut setBackgroundImage:barRevertImagePress forState:UIControlStateHighlighted];
    [m_barRevertBut addTarget:self action:@selector(onRevert) forControlEvents:UIControlEventTouchUpInside];
    
    //前一个按钮
    m_barPriorBut = [[UIButton alloc] initWithFrame:CGRectMake(165.0, 0.0, 55.5, 44.0)];
    UIImage *barPriorImageNormal = [UIImage imageNamed:PIC_MAIL_PRIOR_NORMAL];
    UIImage *barPriorImagePress = [UIImage imageNamed:PIC_MAIL_PRIOR_PRESS];
    [m_barPriorBut setBackgroundImage:barPriorImageNormal forState:UIControlStateNormal];
    [m_barPriorBut setBackgroundImage:barPriorImagePress forState:UIControlStateHighlighted];
    [m_barPriorBut addTarget:self action:@selector(onPrior) forControlEvents:UIControlEventTouchUpInside];
    
    //下一个按钮
    m_barNextBut = [[UIButton alloc] initWithFrame:CGRectMake(215.0, 0.0, 55.5, 44.0)];
    UIImage *barNextImageNormal = [UIImage imageNamed:PIC_MAIL_NEXT_NORMAL];
    UIImage *barNextImagePress  = [UIImage imageNamed:PIC_MAIL_NEXT_PRESS];
    [m_barNextBut setBackgroundImage:barNextImageNormal forState:UIControlStateNormal];
    [m_barNextBut setBackgroundImage:barNextImagePress forState:UIControlStateHighlighted];
    [m_barNextBut addTarget:self action:@selector(onNext) forControlEvents:UIControlEventTouchUpInside];
    
    //操作按钮
    m_barOperateBut = [[UIButton alloc] initWithFrame:CGRectMake(265.0, 0.0, 55.5, 44.0)];
    [m_barOperateBut setTitle:@"" forState:UIControlStateNormal];
    UIImage *barOperateImageNormal = [UIImage imageNamed:PIC_MAIL_DRAG_DOWN_NORMAL];
    UIImage *barOperateImagePress = [UIImage imageNamed:PIC_MAIL_DRAG_DOWN_PRESS];
    [m_barOperateBut setBackgroundImage:barOperateImageNormal forState:UIControlStateNormal];
    [m_barOperateBut setBackgroundImage:barOperateImagePress forState:UIControlStateHighlighted];
    
    [m_barOperateBut addTarget:self action:@selector(onHide) forControlEvents:UIControlEventTouchUpInside];
    
    //添加到navigationbar上
    [m_navBar addSubview:m_barRetBut];
    [m_navBar addSubview:m_barRevertBut];
    [m_navBar addSubview:m_barMergeBut];
    [m_navBar addSubview:m_barPriorBut];
    [m_navBar addSubview:m_barNextBut];
    [m_navBar addSubview:m_barOperateBut];
    [m_barRetBut release];
    [m_barRevertBut release];
    [m_barMergeBut release];

    [m_barOperateBut release];
    //弹出bar
    UIButton *button;
    m_toolDrawerView = [[ToolDrawerView alloc]initInVerticalCorner:kTopCorner andHorizontalCorner:kLeftCorner moving:kVertically];
    [m_toolDrawerView SetSize:47 height:36]; 
    [m_toolDrawerView SetCtlPos:CGPointMake(265, 393)];
    
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate.viewController.view addSubview:m_toolDrawerView];
    
    
    UIImage* imageView = [UIImage imageNamed:PIC_MAIL_DRAG_MENU];
    UIImageView* personImage = [[UIImageView alloc]initWithFrame:CGRectMake(2, -18, 318.5, 72)];
    [personImage setImage:imageView];
    
    [m_toolDrawerView addSubview:personImage];

    //button图片
    UIImage *buttonImageNormal = [UIImage imageNamed:PIC_MAIL_REVERSE_DRAG_MENU_NORMAL];
    UIImage *buttonImagePressed = [UIImage imageNamed:PIC_MAIL_REVERSE_DRAG_MENU_PRESS];
  
    //回复按钮
	button = [UIButton buttonWithType:UIButtonTypeCustom];
	//[button setTitle:@"回复" forState:UIControlStateNormal];
    //设置按钮上的自体的大小
    button.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    [button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
    [button setBackgroundImage:buttonImagePressed forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(onRevert) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件   
	[m_toolDrawerView appendButton:button];
    //[button release];
    
    //转发按钮
	button = [UIButton buttonWithType:UIButtonTypeCustom];
	//[button setTitle:@"转发" forState:UIControlStateNormal];
    //设置按钮上的自体的大小
    button.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    //button图片
    buttonImageNormal = [UIImage imageNamed:PIC_MAIL_TRANSMIT_DRAG_MENU_NORMAL];
    buttonImagePressed = [UIImage imageNamed:PIC_MAIL_TRANSMIT_DRAG_MENU_PRESS];
    [button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
    [button setBackgroundImage:buttonImagePressed forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(onTransmit) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件   
	[m_toolDrawerView appendButton:button];
    //[button release];
    
    //上一封
	m_floatMenuPriorBut = [UIButton buttonWithType:UIButtonTypeCustom];
   // [button setTitle:@"上一封" forState:UIControlStateNormal];
    m_floatMenuPriorBut.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    buttonImageNormal = [UIImage imageNamed:PIC_MAIL_PRIOR_DRAG_MENU_NORMAL];
    buttonImagePressed = [UIImage imageNamed:PIC_MAIL_PRIOR_DRAG_MENU_PRESS];
    [m_floatMenuPriorBut setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
    [m_floatMenuPriorBut setBackgroundImage:buttonImagePressed forState:UIControlStateHighlighted];
    
    [m_floatMenuPriorBut addTarget:self action:@selector(onPrior) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件  
	[m_toolDrawerView appendButton:m_floatMenuPriorBut];
    
    //下一封
	m_floatMenuNextBut = [UIButton buttonWithType:UIButtonTypeCustom];
    //[button setTitle:@"下一封" forState:UIControlStateNormal];
    m_floatMenuNextBut.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    buttonImageNormal = [UIImage imageNamed:PIC_MAIL_NEXT_DRAG_MENU_NORMAL];
    buttonImagePressed = [UIImage imageNamed:PIC_MAIL_NEXT_DRAG_MENU_PRESS];
    [m_floatMenuNextBut setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
    [m_floatMenuNextBut setBackgroundImage:buttonImagePressed forState:UIControlStateHighlighted];
    [m_floatMenuNextBut addTarget:self action:@selector(onNext) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件  
	[m_toolDrawerView appendButton:m_floatMenuNextBut];
    
    //归并按钮
	button = [UIButton buttonWithType:UIButtonTypeCustom];
	//[button setTitle:@"归并" forState:UIControlStateNormal];
    //设置按钮上的自体的大小
    button.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    buttonImageNormal = [UIImage imageNamed:PIC_MAIL_MERGE_DRAG_MENU_NORMAL];
    buttonImagePressed = [UIImage imageNamed:PIC_MAIL_MERGE_DRAG_MENU_PRESS];
    [button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
    [button setBackgroundImage:buttonImagePressed forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(onMerge) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件  
	[m_toolDrawerView appendButton:button];
    //[button release];
    
    //重要按钮
	button = [UIButton buttonWithType:UIButtonTypeCustom];
	//[button setTitle:@"重要" forState:UIControlStateNormal];
    //设置按钮上的自体的大小
    button.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    buttonImageNormal = [UIImage imageNamed:PIC_MAIL_IMPORTANT_DRAG_MENU_NORMAL];
    buttonImagePressed = [UIImage imageNamed:PIC_MAIL_IMPORTANT_DRAG_MENU_PRESS];
    [button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
    [button setBackgroundImage:buttonImagePressed forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(onImportant) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件  
	[m_toolDrawerView appendButton:button];
    //[button release];
    

    
    //隐藏按钮
	button = [UIButton buttonWithType:UIButtonTypeCustom];
	[button setTitle:@"" forState:UIControlStateNormal];
    //设置按钮上的自体的大小
    button.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    buttonImageNormal = [UIImage imageNamed:PIC_MAIL_CLOSE_DRAG_MENU_NORMAL];
    buttonImagePressed = [UIImage imageNamed:PIC_MAIL_CLOSE_DRAG_MENU_PRESS];
    [button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
   
    [button setBackgroundImage:buttonImagePressed forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(onHide) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件  
    
    //[buttonImageNormal release];
    //[buttonImagePressed release];
    
	[m_toolDrawerView appendButton:button];
    
    //隐藏弹出菜单
    m_toolDrawerView.hidden = YES;
    //[button release];
    
    /////////////////////////////////////////////////////////////////////
    
	m_mainView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 44.0, 320.0, 480-20-44-49) style:
                UITableViewStylePlain];
	m_mainView.delegate = self;
	m_mainView.dataSource = self;
	//mainView.scrollEnabled = NO;
	m_mainView.allowsSelection = NO;
	m_rect = m_mainView.frame;
	m_toContainerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
	UILabel *rLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0, 70.0, 44.0)];
	rLabel.text = @"发件人:";
	rLabel.font = [UIFont systemFontOfSize:20];
	rLabel.textColor = [UIColor blackColor];
	[m_toContainerView addSubview:rLabel];
    [rLabel release];
    
    m_dateContainerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
	UILabel *ccLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0, 90.0, 44.0)];
	ccLabel.text = @"发件日期:";
	ccLabel.font = [UIFont systemFontOfSize:20];
	ccLabel.textColor = [UIColor blackColor];
	[m_dateContainerView addSubview:ccLabel];
	[ccLabel release];
	
	m_subjectContainerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
	UILabel *sLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0, 90.0, 44.0)];
	sLabel.text = @"邮件标题:";
	sLabel.font = [UIFont systemFontOfSize:20];
	sLabel.textColor = [UIColor blackColor];
	[m_subjectContainerView addSubview:sLabel];
	[sLabel release];
    
	m_contentContainerView  = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 175.0)];
	UILabel *cLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, 0.0, 90.0, 44.0)];
	cLabel.text = @"邮件内容:";
	cLabel.font = [UIFont systemFontOfSize:20];
	cLabel.textColor = [UIColor blackColor];
	[m_contentContainerView addSubview:cLabel];
	[cLabel release];
    NSString* text =  @"1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的。\n4）如果一个结点是红的，那么它的俩个儿子都是黑的。\n5）对每个结点，从该结点到其子孙结点的所有路径上包含相同数目的黑结点。\n6）对每个结点，从该结点到其子孙结点的所有路径上包含相同数目的黑结点。1）每个结点要么是红的，要么是黑的1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的。\n4）如果一个结点是红的，那么它的俩个儿子都是黑的。\n5）对每个结点，从该结点到其子孙结点的所有路径上包含相同数目的黑结点。1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的。\n4）如果一个结点是红的，那么它的俩个儿子都是黑的。\n5）对每个结点，从该结点到其子孙结点的所有路径上包含相同数目的黑结点1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的。\n4）如果一个结点是红的，那么它的俩个儿子都是黑的。\n5）对每个结点，从该结点到其子孙结点的所有路径上包含相同数目的黑结点1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的@1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的。\n4）如果一个结点是红的，那么它的俩个儿子都是黑的。\n5）对每个结点，从该结点到其子孙结点的所有路径上包含相同数目的黑结点。\n6）对每个结点，从该结点到其子孙结点的所有路径上包含相同数目的黑结点。1）每个结点要么是红的，要么是黑的1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的。\n4）如果一个结点是红的，那么它的俩个儿子都是黑的。\n5）对每个结点，从该结点到其子孙结点的所有路径上包含相同数目的黑结点。1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的。\n4）如果一个结点是红的，那么它的俩个儿子都是黑的。\n5）对每个结点，从该结点到其子孙结点的所有路径上包含相同数目的黑结点1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）每个叶结点，即空结点（NIL）是黑的1）每个结点要么是红的，要么是黑的\n2）根结点是黑的\n3）";
    
    
//    /*根据邮件id,从服务取得邮件的详细信息*/
//    XmlRpc *xml = [[XmlRpc alloc] init];
//    NSString* useid       = [[NSString alloc]initWithString: [[Session share] getMemberID]];
//    NSString* mailShareID = [[NSString alloc]initWithFormat:@"%@",m_mailShareID];
//    NSString* mailID      = [[NSString alloc]initWithFormat:@"%@",m_mailID];
//    
//    //m_mailDetailInfo = [xml getMailDetails:mailShareID mailId:mailID useID:useid]; 
//    
//    NSString *num = [NSString stringWithFormat:@"%i",m_rowIndex];
//    NSString *boxType = [NSString stringWithFormat:@"0%i",m_boxType];
//    m_mailDetailInfo = [xml getMailDetails:mailShareID mailId:mailID useID:useid employee_id:m_mailList.m_employeeID box:boxType startRows:num];
//    
//    if (m_rowIndex < [m_mailList.m_mutableArray count]) 
//    {
//        m_mailListInfo = [m_mailList.m_mutableArray objectAtIndex:m_rowIndex];
//    }
    
    //text = [m_mailDetailInfo objectForKey:@"content_txt"];
    //text = [m_mailDetailInfo objectForKey:@"content"];
//    UIFont *textFont = [UIFont systemFontOfSize:14];
//    CGSize size = [text sizeWithFont:textFont constrainedToSize:CGSizeMake(310.0f, 2500.0f) lineBreakMode:  UILineBreakModeCharacterWrap];
//    
//    m_contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10.0, 44.0, 310.0, size.height)];
//    m_contentLabel.lineBreakMode = UILineBreakModeWordWrap;
//    m_contentLabel.textAlignment = UITextAlignmentLeft;
//    m_contentLabel.numberOfLines = 0;
//	m_contentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(10.0, 44.0, 310.0, size.height)];
//   // m_contentWebView = [[UIWebView alloc]init];
//   
//   // [m_contentWebView loadHTMLString:[m_mailDetailInfo objectForKey:@"content"] baseURL:nil];
////    CGSize actualSize = [m_contentWebView sizeThatFits:CGSizeZero]; 
////    CGRect newFrame = m_contentWebView.frame;
////    CGRect rect = m_contentWebView.frame;
//    m_contentLabel.font = font;
//    m_contentLabel.text = text;
//    [m_contentWebView setDelegate:self];
//	[m_contentContainerView addSubview:m_contentLabel];
    
    //邮件内容
    m_contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(10.0, 44.0, 310.0, 200)];
    m_contentLabel.lineBreakMode = UILineBreakModeWordWrap;
    m_contentLabel.textAlignment = UITextAlignmentLeft;
    m_contentLabel.numberOfLines = 0;
    [m_contentContainerView addSubview:m_contentLabel];
	
	//报题标签
    m_subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(105.0, 0.0, 230.0, 44.0)];
	m_subjectLabel.font = [UIFont systemFontOfSize:18];

	[m_subjectContainerView addSubview:m_subjectLabel];
    [m_subjectLabel release];
 
    
    //发送人标签
    m_sendLabel = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 0.0, 230.0, 44.0)];
	m_sendLabel.font = [UIFont systemFontOfSize:18];
	[m_toContainerView addSubview:m_sendLabel];
    [m_sendLabel release];

    //日期标签
    m_dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(105.0, 0.0, 230.0, 44.0)];
	m_dateLabel.font = [UIFont systemFontOfSize:18];
	[m_dateContainerView addSubview:m_dateLabel];
    [m_dateLabel release];

    //存放button的view
    m_butContainerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 60.0)]; 
    
    //打开附件按钮
	m_attachBut = [UIButton buttonWithType:UIButtonTypeCustom];
	[m_attachBut setTitle:@"" forState:UIControlStateNormal];
    //设置按钮上的自体的大小
    m_attachBut.titleLabel.font = [UIFont systemFontOfSize: 13.0];
    UIImage *buttonImgNormal = [UIImage imageNamed:PIC_MAIL_ATTACH_MESSAGE];
    [m_attachBut setBackgroundImage:buttonImgNormal forState:UIControlStateNormal];
    UIImage *buttonImgPressed = [UIImage imageNamed:PIC_MAIL_ATTACH_MESSAGE];
    [m_attachBut setBackgroundImage:buttonImgPressed forState:UIControlStateHighlighted];
    
    [m_attachBut addTarget:self action:@selector(onAttach) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件
    m_attachBut.frame = CGRectMake(25, 5, 13, 22);
    


    //设置导航栏的工具bar
    UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 235, 45)];

    //设置导航栏背景颜色
    if ([devVersion compare:@"4.3.3"] == 0)
    {
        [tools respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)];
    }else
    {
        [tools setBackgroundImage:imageBar forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    }
    
    [tools setTintColor:[self.navigationController.navigationBar tintColor]]; 
    [tools setAlpha:[self.navigationController.navigationBar alpha]]; 
    NSMutableArray* butArray = [[NSMutableArray alloc] initWithCapacity:2];
    
    
    UIBarButtonItem *operateBut = [[UIBarButtonItem alloc] 
                                     initWithTitle:@"操作" style:UIBarButtonItemStylePlain target:self action:@selector(onHide)]; 
    UIBarButtonItem *mergeBut = [[UIBarButtonItem alloc] 
                                   initWithTitle:@"归并" style:UIBarButtonItemStylePlain target:self action:nil]; 
    UIBarButtonItem *responseBut = [[UIBarButtonItem alloc] 
                                 initWithTitle:@"回复" style:UIBarButtonItemStylePlain target:self action:nil]; 
    
    UIBarButtonItem *leftBut = [[UIBarButtonItem alloc] 
                                 initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil]; 
    UIBarButtonItem *rightBut = [[UIBarButtonItem alloc] 
                                    initWithTitle:@"回复" style:UIBarButtonItemStylePlain target:self action:nil]; 
    [butArray addObject:responseBut]; 
    [responseBut release]; 
    
    [butArray addObject:mergeBut]; 
    [mergeBut release]; 
    
    [butArray addObject:leftBut]; 
    [leftBut release];
    
    [butArray addObject:rightBut]; 
    [rightBut release];
    
 
    
    [butArray addObject:operateBut];        
    [operateBut release];
    
    [tools setItems:butArray animated:NO]; 
    [butArray release]; 
    UIBarButtonItem *butItem = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
    self.navigationItem.rightBarButtonItem = butItem;
    //self.navigationItem.titleView = butContainerView;
    [butItem release]; 
    [tools release];

    
	//[self.view insertSubview:mainView belowSubview:self.navBar];    //偏移改变.
    //[self.view addSubview:topnavBar];
    [self.navigationController.view addSubview:m_navBar]; 
    [self.view addSubview:m_mainView];
    NSLog(@"[MailDetailMessage]-[viewDidLoad]---end");
} 

- (void)webViewDidFinishLoad:(UIWebView *) webView
{
    CGSize actualSize = [webView sizeThatFits:CGSizeZero];
    
    CGRect newFrame = webView.frame;
    newFrame.size.height = actualSize.height;
    webView.frame = newFrame;
}
#pragma mark -----View显示和消失处理函数-----

//******************************************************
// Method:     viewDidDisappear
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)viewDidDisappear:(BOOL)animated
{
    //toolDrawerView.hidden = YES;
    //[self cancelData];
}

//******************************************************
// Method:     viewWillDisappear
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)viewWillDisappear:(BOOL)animated
{
    m_toolDrawerView.hidden = YES;
}

//******************************************************
// Method:     viewWillAppear
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)viewWillAppear:(BOOL)animated
{
    //[self.navigationController setNavigationBarHidden:NO];
    //[self.navigationController.navigationBar setHidden:YES];
    [self.m_navBar isHidden];
}
- (void)viewDidAppear:(BOOL)animated
{
    [self refreshData];
}

#pragma mark ----弹出菜单----

//******************************************************
// Method:     onReturn
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   返回到上一个页面
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onReturn
{
    //[m_condition lock];
    m_bIsBack = YES;
    [[[TaskManager Share] GetTaskByType:GetMailList Delegate:self] cancel]; 
    self.m_navBar.hidden = YES;
    [self.navigationController setNavigationBarHidden:YES];
    [self.navigationController popViewControllerAnimated:YES];
    
    //[m_condition unlock];
}

//******************************************************
// Method:     onDelete
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   //删除
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onDelete
{
    XmlRpc *xml = [[XmlRpc alloc] init];
    [xml deleteMail:m_mailShareID];
    [xml release];
    
}

//******************************************************
// Method:     onDelete
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   //回复
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onRevert
{
    MailMessageComposer *msgC = [[MailMessageComposer alloc] initWithNibName:
                                 @"MailMessageComposer" bundle:nil];
    msgC.m_mailComType = REVERSE_COMPOSER;
    //保存邮件详细页面的指针
    [msgC setMailDetailObj:self];
    
    //跳转页面后，禁止滑动事件
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    NavigationMainViewController* mainNavView = [appDelegate getMainViewCtl];
    
    mainNavView.m_nav.motionDelegate = nil;
    
    
    [self.navigationController setNavigationBarHidden:YES];
    
    [self.navigationController pushViewController:msgC animated:YES];
    [msgC release];
    
    NSLog(@"onRevert");
}
//******************************************************
// Method:     getMailAddress
// Access:     public 
// Returns:    NSString
// Parameter:  originMailAddr
// Note:	   去掉 < > 提取邮件地址
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(NSString*) getMailAddress:(NSString*) originMailAddr
{
    NSString* temp    = originMailAddr;
    NSString *strSplit = temp;//@"<m>missed call</m>";
    NSRange rsrange;
    rsrange.length   = 0;
    rsrange.location = 0;//index是在头文件中申请好的全局变量.int型 初始值为0
    NSRange xrange = [strSplit rangeOfString:@"<"];
    if (xrange.length ==0)
    {
        return @"";
    }
    int x = xrange.location;
    
    NSRange yrange = [strSplit rangeOfString:@">"];
    
    int y = yrange.location;
    NSString *result = [strSplit substringFromIndex:x+1];
    result = [result substringToIndex:y-x-1];
    return result;
}
//******************************************************
// Method:     onDelete
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   //归并
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onMerge
{
    /*归并邮件*/
    XmlRpc *xml = [[XmlRpc alloc] init];   
    NSMutableDictionary * mergeNewMailParm = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                    m_mailShareID,@"mail_share_ids",
                                             nil];
    
    NSMutableDictionary* dicRet = [xml settingMultiMerger:mergeNewMailParm];
    if (dicRet == nil)
    {
        return;
    }
    //返回不能归并的邮p件地址
    NSString*  error_message = [dicRet objectForKey:@"error_message"]; 
    NSArray *  arrayMerge   = [error_message componentsSeparatedByString:@","];
    
    //如果有没有归并的邮件弹出提示
    if ([arrayMerge count] > 0)
    {
        //[m_checkedArray removeAllObjects];
        NSString* strToast = @"您的邮件，无法归并";
        [myToast showWithText:strToast];
    }
    
    [mergeNewMailParm release];
    [xml release];
    
}

//******************************************************
// Method:     onTransmit
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   //转发
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void)onTransmit    
{
    MailMessageComposer *msgC = [[MailMessageComposer alloc] initWithNibName:
                                 @"MailMessageComposer" bundle:nil];
    msgC.m_mailComType = TRANSMIT_COMPOSER;
    
    //保存邮件详细页面的指针
    [msgC setMailDetailObj:self];
    
    //跳转页面后，禁止滑动事件
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    NavigationMainViewController* mainNavView = [appDelegate getMainViewCtl];
    
    mainNavView.m_nav.motionDelegate = nil;
    
    
    [self.navigationController setNavigationBarHidden:YES];
    
    [self.navigationController pushViewController:msgC animated:YES];
    [msgC release];
    
    NSLog(@"onRevert");
}

//******************************************************
// Method:     onImport
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   //重要
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onImportant
{
    XmlRpc *xml = [[XmlRpc alloc] init];
    BOOL bSuccess = [xml settingMailImportantFlag:m_mailShareID employId:m_mailList.m_employeeID importantFlag:@"1"]; 
    if (bSuccess) 
    {
        if (m_rowIndex < [m_mailList.m_mutableArray count]) 
        {
            NSMutableDictionary* listDic = [m_mailList.m_mutableArray objectAtIndex:m_rowIndex];
            [listDic setObject:@"1" forKey:@"importantflag"];   
        }

        
    }
    [xml release];
}
//******************************************************
// Method:     onImport
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   //上一个
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onPrior
{
    m_bNextPriorDetail = YES;
    int rowIndex = --m_rowIndex;
    if (rowIndex < 0)
    {
        m_floatMenuPriorBut.enabled = NO;     //弹出菜单上的前一个按钮
        m_barPriorBut.enabled       = NO;     //前一个按钮
        m_rowIndex = 0;
        return;
    }else
    {
        m_floatMenuNextBut.enabled = YES;      
        m_barNextBut.enabled       = YES; 
    }
    [self refreshData];
//    NSString *num = [NSString stringWithFormat:@"%i",rowIndex];
//    NSString *boxType = [NSString stringWithFormat:@"0%i",m_boxType];
//    
//    XmlRpc *xml = [[XmlRpc alloc] init];
//    //保存来自服务器中的数据
//    NSMutableDictionary *tmpMailListArray  = [xml GetNextPriorDetailMail:m_mailList.m_employeeID  box:boxType startRows:num]; 
//    
//    NSMutableDictionary *mailListArray = [[NSMutableDictionary alloc] initWithDictionary:tmpMailListArray];
//    [xml release];
//    
//    m_mailDetailInfo = mailListArray;
//    
//    m_subjectLabel.text = [m_mailDetailInfo objectForKey:@"subject"];
//    m_sendLabel.text = [m_mailDetailInfo objectForKey:@"sendaddress"];
//    m_dateLabel.text = [m_mailDetailInfo objectForKey:@"receive_send_time"];
    //[mailListArray release];
}

//******************************************************
// Method:     onImport
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   //下一个
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onNext
{
    m_bNextPriorDetail = YES;
//    NSString *num = [NSString stringWithFormat:@"%i",++m_rowIndex];
//    NSString *boxType = [NSString stringWithFormat:@"0%i",m_boxType];
//
//    XmlRpc *xml = [[XmlRpc alloc] init];
//    //保存来自服务器中的数据
//    NSMutableDictionary *tmpMailListArray  = [xml GetNextPriorDetailMail:m_mailList.m_employeeID  box:boxType startRows:num]; 
//    
//    NSMutableDictionary *mailListArray = [[NSMutableDictionary alloc] initWithDictionary:tmpMailListArray];
//    [xml release];
//    
    if (m_mailDetailInfo == nil) 
    {
        m_floatMenuNextBut.enabled = NO;      
        m_barNextBut.enabled       = NO; 
        --m_rowIndex;
        return;
    }
    else
    {
        m_floatMenuPriorBut.enabled = YES;     //弹出菜单上的前一个按钮
        m_barPriorBut.enabled       = YES;            //前一个按钮
    }
//    
//    m_mailDetailInfo = mailListArray;
//    m_subjectLabel.text = [m_mailDetailInfo objectForKey:@"subject"];
//    m_sendLabel.text = [m_mailDetailInfo objectForKey:@"sendaddress"];
//    m_dateLabel.text = [m_mailDetailInfo objectForKey:@"receive_send_time"];
    //[mailListArray release];
    
    ++m_rowIndex;
    [self refreshData];
}

//******************************************************
// Method:     onImport
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   //取消
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onHide
{
    if ([m_toolDrawerView isHidden] == YES) 
    {
        
        m_toolDrawerView.hidden = NO;
    }
    else
    {
        m_toolDrawerView.hidden = YES;
    }
}
#pragma mark -附件按钮

//******************************************************
// Method:     onImport
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   //打开附件按钮
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) onAttach:(id)sender
{
    UIButton* button = (UIButton*)sender;
    NSString* attachmentID = button.accessibilityHint;
    NSLog(@"%@",attachmentID);
    
	WebViewContrller *WebView = [[WebViewContrller alloc] init];
    
    //设置title的文件名字和文件id
    NSString* title  = button.accessibilityLabel;
    WebView.m_title  = title;
    WebView.m_fileID = attachmentID;
    
	NSUserDefaults *UserDefaults = [NSUserDefaults standardUserDefaults];
	[UserDefaults setInteger:WebView.URLPage forKey:@"PageKey"];
    
    [self.navigationController setNavigationBarHidden:YES];
	[self.navigationController pushViewController:WebView animated:NO];
	[WebView release];
}

//******************************************************
// Method:     textFieldShouldReturn
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	  
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

//******************************************************
// Method:     textViewShouldReturn
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	  
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(BOOL)textViewShouldReturn:(UITextView *)textView
{
    [textView resignFirstResponder];
    return YES;
}

//******************************************************
// Method:     viewDidUnload
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	  
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)viewDidUnload 
{
    [[[TaskManager Share] GetTaskByType:GetMailList Delegate:self] cancel]; 
 
    [super viewDidUnload];
    self.m_navBar = nil;
}

//******************************************************
// Method:     dealloc
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	  
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (void)dealloc 
{
	[m_toContainerView release];
	[m_contentWebView release];
	[m_subjectLabel release];
    [m_dateContainerView release];
	[m_mainView release];
	[m_navBar release];
	[super dealloc];
}

#pragma mark -

//******************************************************
// Method:     tableView
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	  
// Author      muzongcun  2012/03/12 create
//*******************************************************
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	switch (indexPath.row) 
	{
		case 0:
			return m_toContainerView.frame.size.height;
		case 1:
			return m_dateContainerView.frame.size.height;;
            
        case 2:
			return 44.0;
		case 3:
        {
            NSString* text = [m_mailDetailInfo objectForKey:@"content_txt"];
            //  NSLog(@"%@",text);
            UIFont *textFont = [UIFont systemFontOfSize:14];
            CGSize size = [text sizeWithFont:textFont constrainedToSize:CGSizeMake(310.0f, 2500.0f) lineBreakMode:  UILineBreakModeCharacterWrap];
            
            CGFloat height = size.height + 150;
			return height;
        }
	}
	return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
	static NSString *CellIdentifier = @"Cell";

	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (cell == nil) 
	{
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
	}
	
	if(indexPath.row == 0)
	{
        [m_toContainerView removeFromSuperview];
        if (m_bThreadFresh == YES) 
        {
            m_sendLabel.text = [m_mailDetailInfo objectForKey:@"sendaddress"];
        }
		[cell.contentView addSubview:m_toContainerView];
	}
    
    if(indexPath.row == 1)
	{
        [m_dateContainerView removeFromSuperview];
        if (m_bThreadFresh == YES) 
        {
            m_dateLabel.text = [m_mailDetailInfo objectForKey:@"receive_send_time"];
        }
		[cell.contentView addSubview:m_dateContainerView];
	}
	if(indexPath.row == 2)
	{
        [m_subjectContainerView removeFromSuperview];
        if (m_bThreadFresh == YES) 
        {
            m_subjectLabel.text = [m_mailDetailInfo objectForKey:@"subject"];
        }
		[cell.contentView addSubview:m_subjectContainerView];
	}
	if(indexPath.row == 3)
	{
        [m_contentLabel removeFromSuperview];
        UIFont *font              = [UIFont systemFontOfSize:14];
        NSString* text = nil;
        
        if(m_bThreadFresh == YES)
        {
            text = [m_mailDetailInfo objectForKey:@"content_txt"];
            UIFont *textFont = [UIFont systemFontOfSize:14];
            CGSize size = [text sizeWithFont:textFont constrainedToSize:CGSizeMake(310.0f, 2500.0f) lineBreakMode:  UILineBreakModeCharacterWrap];
            
            m_contentLabel.frame = CGRectMake(10.0, 44.0, 310.0, size.height);
            m_contentLabel.lineBreakMode = UILineBreakModeWordWrap;
            m_contentLabel.textAlignment = UITextAlignmentLeft;
            m_contentLabel.numberOfLines = 0;

            m_contentLabel.font = font;
            m_contentLabel.text = text;

            [m_contentContainerView addSubview:m_contentLabel];
        }

		[cell.contentView addSubview:m_contentContainerView];
	}
	return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    if (m_bThreadFresh != YES) 
    {
        return @"";
    }
    
    UIView* footView =  m_mainView.tableFooterView;
    if (footView == nil) {
        
        NSString* attachname   = [m_mailDetailInfo objectForKey:@"attachname"];
        NSString* attachmentID = [m_mailDetailInfo objectForKey:@"attachmentID"];
        NSArray * attachIDArray =   [attachmentID componentsSeparatedByString:@","];
        NSArray * attachNameArray =   [attachname componentsSeparatedByString:@","];
        
        NSLog(@"attachname= %@",attachname);
        
        int attachButXPos = 15;   //X坐标
        int attachButYPos = 10;   //y坐标
        int count = 0;
        if ([attachmentID compare:@""] != 0) 
        {
            if ([attachNameArray count] >0) 
            {
                for (id object in attachNameArray) 
                {
                    NSString* strName = object;
                    //打开附件按钮图标
                    /*********************************************************/
                    m_attachBut = [UIButton buttonWithType:UIButtonTypeCustom];
                    NSString* attachmentID = @"";
                    if (count < [attachIDArray count]) 
                    {
                        attachmentID =[attachIDArray objectAtIndex:count];
                    }
                    
                    m_attachBut.accessibilityHint= attachmentID;
                    m_attachBut.accessibilityLabel = strName;
                    
                    //[m_attachBut setTitle:@"" forState:UIControlStateNormal];
                    //设置按钮上的自体的大小
                    m_attachBut.titleLabel.font = [UIFont systemFontOfSize: 18.0];
                    UIImage *buttonImgNormal = [UIImage imageNamed:PIC_MAIL_ACCESSORY];
                    [m_attachBut setBackgroundImage:buttonImgNormal forState:UIControlStateNormal];
                    UIImage *buttonImgPressed = [UIImage imageNamed:PIC_MAIL_ACCESSORY];
                    [m_attachBut setBackgroundImage:buttonImgPressed forState:UIControlStateHighlighted];
                    
                    [m_attachBut addTarget:self action:@selector(onAttach:) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件
                    m_attachBut.frame = CGRectMake(attachButXPos, attachButYPos, 13, 22);
                    
                    //打开附件名字
                    /*********************************************************/
                    m_attachNameBut = [[UIButton alloc] initWithFrame:CGRectMake(0, 0.0, 70, 22.0)];
                    m_attachNameBut.accessibilityHint= attachmentID;
                    m_attachNameBut.accessibilityLabel = strName;
                    UIFont *font               = [UIFont systemFontOfSize:18];
                    CGSize size = [strName sizeWithFont:font constrainedToSize:CGSizeMake(310.0f, 2500.0f) lineBreakMode:  UILineBreakModeCharacterWrap];
                    m_attachNameBut.frame = CGRectMake(attachButXPos+20, attachButYPos, size.width+8, 22+8);
                    
                    [m_attachNameBut setTitle:strName forState:UIControlStateNormal];
                    font              = [UIFont systemFontOfSize:18];
                    m_attachNameBut.titleLabel.font = font;
                    [m_attachNameBut setTitleColor:[UIColor colorWithRed:56/255.0 green:191/255.0 blue:255/255.0 alpha:1.0] forState:UIControlStateNormal]; 
                    [m_attachNameBut addTarget:self action:@selector(onAttach:) forControlEvents:UIControlEventTouchUpInside];  //设置按钮点击事件
                    buttonImgPressed = [UIImage imageNamed:PIC_MAIL_CONTACE_NAME_BG];
                    [m_attachNameBut setBackgroundImage:buttonImgPressed forState:UIControlStateHighlighted];
                    attachButYPos += 35;
                    
                    // 计算附件的位置,调整view的大小
                    // 附件图片的宽度＝附件本身的宽度＋文本的宽度
                    //                attachButXPos += size.width + 15;
                    //                if (320 - attachButXPos < size.width) 
                    //                {
                    //                    attachButYPos += 25;
                    //                    attachButXPos = 15;
                    //                    CGRect rect = m_butContainerView.frame;
                    //                    rect.size.height += 15;
                    //                    m_butContainerView.frame = rect;
                    //                }
                    
                    CGRect rect = m_butContainerView.frame;
                    rect.size.height += 30;
                    m_butContainerView.frame = rect;
                    
                    //添加到tableFooterView上
                    [m_butContainerView addSubview:m_attachBut];
                    [m_butContainerView addSubview:m_attachNameBut];
                    count++;
                }
                m_mainView.tableFooterView = m_butContainerView;
            } 
        } 
    }
    return @"";
}
#pragma mark -


-(void)dismissTipAlert:(NSTimer*)ti
{
	[m_tipTimer invalidate];
	[m_tipAlert dismissWithClickedButtonIndex:0 animated:YES];
	[m_tipAlert release];
}

#pragma mark - MailListCell
-(void) SetMailShareID:(NSString*) strShareID mailID:(NSString*)strMailID rowIndex:(int)rowIndex boxType:(int)boxType
{
    m_boxType       =   boxType;
    m_rowIndex      =   rowIndex;
    m_mailShareID   =   strShareID;
    m_mailID        =   strMailID;
}

#pragma mark - my func
//******************************************************
// Method:     refreshData
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void)refreshData
{
    NSLog(@"refresh data");
    [[[TaskManager Share] GetTaskByType:GetMailList Delegate:self] Excute]; 
    
    //开始菊花转动
    m_spinner = [[TKLoadingAnimationView alloc] initWithFrame:CGRectMake(140, 215, 30, 30) 
                                  tkLoadingAnimationViewStyle:TKLoadingAnimationViewStyleCarton];
	
	[self.view addSubview:m_spinner];
	[m_spinner startAnimating];
	[m_spinner release];
}
//******************************************************
// Method:     refreshData
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void)cancelData
{
    NSLog(@"cancel data");
    [[[TaskManager Share] GetTaskByType:GetMailList Delegate:self] cancel]; 
}

//******************************************************
// Method:     getMoreData
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) getMoreData
{
    NSLog(@"more data");
}

//******************************************************
// Method:     OnPreExcute
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) OnPreExcute
{
    m_barRetBut.enabled     = NO;   
    m_barRevertBut.enabled  = NO;
    m_barMergeBut.enabled   = NO; 
    m_barPriorBut.enabled   = NO;
    m_barNextBut.enabled    = NO;
    m_barOperateBut.enabled = NO; 
}
//******************************************************
// Method:     DoInBackground
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) DoInBackground
{
    //[m_condition lock];
    /*根据邮件id,从服务取得邮件的详细信息*/
    m_bThreadFresh = YES;
    
    XmlRpc *xml = [[XmlRpc alloc] init];
    NSString* useid       = [[NSString alloc]initWithString: [[Session share] getMemberID]];
    NSString* mailShareID = [[NSString alloc]initWithFormat:@"%@",m_mailShareID];
    NSString* mailID      = [[NSString alloc]initWithFormat:@"%@",m_mailID];
    NSString *num = [NSString stringWithFormat:@"%i",m_rowIndex];
    NSString *boxType = [NSString stringWithFormat:@"0%i",m_boxType];
    //m_mailDetailInfo = [xml getMailDetails:mailShareID mailId:mailID useID:useid]; 
    
    if (m_bNextPriorDetail == YES) 
    {
        m_bNextPriorDetail = NO;
        //保存来自服务器中的数据
        m_mailDetailInfo  = [xml GetNextPriorDetailMail:m_mailList.m_employeeID  box:boxType startRows:num]; 
        
    }else
    {

        [m_mailDetailInfo removeAllObjects];
        m_mailDetailInfo = [xml getMailDetails:mailShareID mailId:mailID useID:useid employee_id:m_mailList.m_employeeID box:boxType startRows:num];
    }
        
    if (m_mailDetailInfo != nil) 
    {
        if (m_bIsBack == NO)
        {
            [m_mainView reloadData];
        }
        
    } 
    //[m_condition unlock];

}

//******************************************************
// Method:     OnPostExcute
// Access:     public 
// Returns:    void
// Parameter:  
// Note:	   
// Author      muzongcun  2012/03/12 create
//*******************************************************
-(void) OnPostExcute
{
    m_barRetBut.enabled     = YES;   
    m_barRevertBut.enabled  = YES;
    m_barMergeBut.enabled   = YES; 
    m_barPriorBut.enabled   = YES;
    m_barNextBut.enabled    = YES;
    m_barOperateBut.enabled = YES; 
    [m_spinner stopAnimating];
}
@end
